package com.hujing.springsource.a04;

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;
import org.springframework.context.annotation.ContextAnnotationAutowireCandidateResolver;
import org.springframework.context.support.GenericApplicationContext;

public class A04Application {

    public static void main(String[] args) {
        //定义一个干净的容器
        GenericApplicationContext context = new GenericApplicationContext();

        //注册bean
        context.registerBean("bean1",Bean1.class);
        context.registerBean("bean2",Bean2.class);
        context.registerBean("bean3",Bean3.class);
        context.registerBean("bean4",Bean4.class);

        //添加处理@Autowired,@Value注解的后处理器
        context.getDefaultListableBeanFactory().setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
        context.registerBean(AutowiredAnnotationBeanPostProcessor.class);

        //添加处理@Resource,@PostConstruct,@PreDestroy注解的后处理器
        context.registerBean(CommonAnnotationBeanPostProcessor.class);

        //注册处理@ConfigurationProperties的处理器
        ConfigurationPropertiesBindingPostProcessor.register(context.getDefaultListableBeanFactory());

        //初始化容器
        context.refresh();

        System.out.println(context.getBean(Bean4.class));

        //销毁容器
        context.close();
    }
}
